<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.jstl.User" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<html>
<head>
    <title>JSTL使用</title>
</head>
<body>
    <%
      List<User> users = new ArrayList<>();
      User u1 = new User("李白",28);
      users.add(u1);
      User u2 = new User("杜甫",18);
      users.add(u2);
      User u3 = new User("高适",32);
      users.add(u3);
      pageContext.setAttribute("userList",users);
      pageContext.setAttribute("lb",u1);
    %>
    <h2>----表达式----</h2>
    c:out:
    <br/>
    <c:out value="${lb}" default="default_libai" />
    <br/>
    <c:out value="${lb.username}" >
        default_libai
    </c:out>
    <br/>
    <br/>
    c:set:
    <br/>
    <c:set var="coures"  value="Java Web"/>
    <br/>
    ${coures}
    <br>
    <c:set var="coures2"  >
        企业后端开发技术
    </c:set>
    <br/>
    ${coures2}
    <br/>
    <c:set value="10086" target="${lb}" property="mobile"/>
    ${lb.mobile}
    <br/>
    <c:set target="${lb}" property="mobile">
        10010
    </c:set>
    ${lb.mobile}
    <br/>
    c:remove
    <br/>
    <c:remove var="coures"/>
    ${coures}
    <br/>
    c:catch:
    <br/>
    <c:catch var ="catchException">
        <% int x = 5/0;%>
    </c:catch>
    <c:if test = "${catchException != null}">
        <p>异常为 : ${catchException} <br />
            发生了异常: ${catchException.message}</p>
    </c:if>
    <br/>
    <h2>----URL相关标签  ----</h2>
    c:import
    <br/>
    <c:import url="MydoGet">
        <c:param name="test" value="www.baidu.com"  />
    </c:import>
    <br/>
    c:url
    <br/>
    <c:url value="MydoGet" var="myurl">
        <c:param name="test" value="www.qq.com"  />
    </c:url>
    <br/>
    <a href="<c:out value="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/${myurl}"/>"> myurl </a>
    <br/>

    <h2>----流程控制标签 ----</h2>
    <br/>
    <c:if test="${userList.size()>0}" var="listNotIsEmpty" />
    userList是否有元素：${listNotIsEmpty}
    <br/>
    <c:if test="${not empty userList&&userList.size()>0}" var="b1" >
            ${userList.get(0).username}
    </c:if>
    <br/>
    c:choose
    <br/>
    <%request.setAttribute("score", "59"); %>
    <c:choose>
        <c:when test="${score>=90}">优秀</c:when>
        <c:when test="${score>=80&&score<90}">良好</c:when>
        <c:when test="${score>=70&&score<80}">中等</c:when>
        <c:when test="${score>=60&&score<70}">及格</c:when>
        <c:otherwise>不及格</c:otherwise>
    </c:choose>


    <h2>----循环标签 ----</h2>
   c:foreach：
    <table  style="border:1px solid gray;">
        <td >
            <td>序号</td>
            <td>姓名</td>
        </td>
        <c:forEach items="${userList}" var="item" varStatus="status">
            <tr >
                <td>${status.count}</td>
                <td>${item.username}</td>
            </tr>
        </c:forEach>
    </table>
    <br/>
    c:forTokens：
    <br/>
    <%
        pageContext.setAttribute("msg", "这#是#一个#forTakons#示#例");
    %>
    <c:forTokens items="${msg}" delims="#" var="msg" begin="0" end="3" step="1">
        ${msg}<br>
    </c:forTokens>







</body>
</html>
